#ifndef UIMANAGER_H
#define UIMANAGER_H

#include <QObject>
#include <QThread>
#include <QDebug>
#include "Task/register.h"
#include"Task/login.h"
#include"Account/account.h"
#include"Socket/Package.h"
#include"servermessageadapter.h"
class UIManager : public QObject
{
    Q_OBJECT
public:

    static UIManager* getInstance()
    {
        if(ui_manager==nullptr)
            ui_manager = new UIManager();
        return ui_manager;
    }

signals:
    void resultReady(const QString &str); // 向外界发送结果
    void sig_test(Package::RegisterRequestSend);
    void sig_test(Package::LoginRequestSend);
    void sig_phone_check(Package::ChecknumRequestSend);
    void sig_register(Package::RegisterRequestSend);
    void sig_login(Package::LoginRequestSend);
    void sig_add_friend(Package::AddFriendRequestSend);
    void sig_InfoSync();
    void sig_send_msg(Package::MessageSend);
    void sig_sync_msg(Package::MessageHistoryRequestSend);
    void sig_agree_friend(Package::AgreeToAddFriendStatus);
    void sig_agree_group(Package::AgreeToGroupStatus);
    void sig_create_group(Package::CreateGroup);
private:
    explicit UIManager(QObject *parent = nullptr);
    static UIManager* ui_manager;

    AbstractTask* now_task;
    int getServerMessage();
    void solveServerMessage();
    int count=0;
public slots:
    void run(); // 耗时操作
    void addTaskLogin(QString uid,QString passwd);
    void addphone(QString phone);
    void LoginSuccess(QString name,QString uid,QString passwd);
    void registerRequest(QString phone,QString name,QString passwd,QString check_str);
    void addFriend(QString friend_id);
    void infoSyncRequest();
    void sendMessage(QString,QString);
    void sendMessageGroup(QString,QString,QString);
    void msgSyncRequest(QString uid_me);
    void agreeToGroup(QString uid,QString gid,bool is_agree);
    void createGroup();


};

#endif // UIMANAGER_H
